function changeTime(date) {
    var dateee = new Date(date).toJSON();
    return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') 
}
// 创建节点的函数，与创建页面的的功能类似都用于创建存储动态的节点，但表现形式不同
// 第一个参数是相应报文，第二个是a按钮的字符串，用法与创建页面的函数类似,第三个是存放动态的容器
function createNode(response, a_string, dynamicWrapper) {
    // var dynamicWrapper = document.getElementById("dynamic-wrapper");
    var load = document.getElementById("load");
    var pageWrapper = document.getElementById("pageWrapper");
    if (response.data) {
        var obj = response.data;
    } else {
        obj = response;
    }
    if (pageWrapper) {
        pageWrapper.style.display = "none"
    }
    // temp用于记住当前展现出的最后一个动态
    let i, temp = 0;
    for (i = 0; i < temp + 4 && i < obj.length; i++) {
        var F_div = document.createElement("div");
        var h2 = document.createElement("h2");
        var span = document.createElement("span");
        var a = document.createElement("a");
        var h3 = document.createElement("h3");
        var S_div = document.createElement("div");
        var p = document.createElement("p");
        span.innerHTML = obj[i].id;
        var time = changeTime(obj[i].creationTime);
        console.log(time);
        h2.innerHTML = '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + obj[i].username + '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + time;
        h3.innerHTML = obj[i].title;
        p.innerHTML = obj[i].content;
        S_div.appendChild(span);
        S_div.appendChild(h2);
        // 如果a的字符串参数存在，则a存在，否则不插入每个节点，即不提供删除功能
        if (a_string == "") {
            a.style.display = "none";
        } else {
            a.innerHTML = a_string;
            S_div.appendChild(a);
        }
        S_div.appendChild(h3);
        S_div.appendChild(p);
        if (obj[i].hasPicture == 1) {
            var img = document.createElement("img");
            img.src = "http://www.rushmc.top/" + obj[i].urls[0];
            S_div.appendChild(img);
        }
        F_div.appendChild(a);
        F_div.appendChild(S_div);
        a.onclick = function (event) {
            var dynamicId = event.target.nextElementSibling.firstElementChild.innerHTML;
            ajax({
                type: "post",
                url: "http://www.rushmc.top/api/dynamicState/delete",
                data: {
                    id: dynamicId
                },
                success: function (response) {
                    event.target.style.color = "red";
                    event.target.innerHTML = "删除成功！";
                    setTimeout(() => {
                        event.target.parentNode.style.display = "none";
                    }, 1000);
                }
            })
        }
        S_div.onclick = function (event) {
            event.cancelBubble = 'true';
            if (event.target.innerHTML) {
                var dynamicid = event.target.firstChild.innerHTML;
            }
            if (!dynamicid) {
                dynamicid = event.target.parentNode.firstChild.innerHTML;
            }
            setSession("dynamicid", dynamicid);
            document.location = "../" + "动态详情/index5.html";
        }
        dynamicWrapper.appendChild(F_div);
    }
    if (obj.length <= 5 || i == obj.length) {
        load.innerHTML = "暂无更多数据";
    } else {
        load.innerHTML = "加载更多内容";
    }
    temp = i;
    // 加载更多的按钮，点击加载更多的动态
    load.onclick = function () {
        for (i; i < temp + 4 && i < obj.length; i++) {
            var F_div = document.createElement("div");
            var h2 = document.createElement("h2");
            var span = document.createElement("span");
            var a = document.createElement("a");
            var h3 = document.createElement("h3");
            var S_div = document.createElement("div");
            var p = document.createElement("p");
            span.innerHTML = obj[i].id;
            var time = changeTime(obj[i].creationTime);
        h2.innerHTML = '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + obj[i].username + '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + '&nbsp' + time;
            if (a_string == null) {
                a.style.display = "none";
            } else {
                a.innerHTML = a_string;
            }
            h3.innerHTML = obj[i].title;
            p.innerHTML = obj[i].content;
            S_div.appendChild(span);
            S_div.appendChild(h2);
            S_div.appendChild(h3);
            S_div.appendChild(p);
            if (obj[i].hasPicture == 1) {
                var img = document.createElement("img");
                img.src = "http://www.rushmc.top/" + obj[i].urls[0];
                S_div.appendChild(img);
            }
            F_div.appendChild(a);
            F_div.appendChild(S_div);
            S_div.onclick = function (event) {
                event.cancelBubble = 'true';
                let dynamicid = event.target.firstChild.innerHTML;
                if (!dynamicid) {
                    dynamicid = event.target.parentNode.firstChild.innerHTML;
                }
                setSession("dynamicid", dynamicid);
                document.location = "../" + "动态详情/index5.html";
            }
            a.onclick = function (event) {
                var dynamicId = event.target.nextElementSibling.firstElementChild.innerHTML;
                ajax({
                    type: "post",
                    url: "http://www.rushmc.top/api/dynamicState/delete",
                    data: {
                        id: dynamicId
                    },
                    success: function (response) {
                        event.target.style.color = "red";
                        event.target.innerHTML = "删除成功！";
                        setTimeout(() => {
                            event.target.parentNode.style.display = "none";
                        }, 1000);
                    }
                })
            }
            dynamicWrapper.appendChild(F_div);
        }
        temp = i;
        if (obj.length <= 5 || i == obj.length) {
            load.innerHTML = "暂无更多数据";
        } else {
            load.innerHTML = "加载更多内容"
        }
    }

}